﻿#region 命名空间

using System;
using System.Collections.Generic;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using WinnerCMS.BLL;
using WinnerCMS.Common;
using WinnerCMS.Model.Attribute;

#endregion

namespace WinnerCMS.WebUI.Admin.Task
{
    [Access("266003")]
    public partial class Setting : WebFactory.PageBase
    {
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
                ReadTaskConfigXML();
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            var ErrMsg = "";
            try
            {
                WriteTaskConfigXML();
            }
            catch (Exception Ex)
            {
                ErrMsg = (Ex.Message.Replace(@"\", @"\\"));
            }
            if (ErrMsg.Length == 0)
            {
                MsgBox.Message("操作完成！", this.UpdatePanel1);
            }
            else
            {
                MsgBox.Message(ErrMsg, this.UpdatePanel1);
            }
        }

        #region Task

        private void ReadTaskConfigXML()
        {
            var config = CMSConfig.Instance();
            this.txtTimerMinutesInterval.Text = config.Scheduler.TimerMinutesInterval.ToString();

            this.cbkEnabled.Checked = config.Scheduler.Enabled;
        }

        private void WriteTaskConfigXML()
        {
            var config = CMSConfig.Instance();
            config.Scheduler.TimerMinutesInterval = int.Parse(this.txtTimerMinutesInterval.Text);
            config.Scheduler.Enabled = this.cbkEnabled.Checked;
            config.Save(config);
        }

        #endregion
    }
}